//
//  CreateGroupActiveTableViewCell.m
//  Findif
//
//  Created by Mac on 2019/3/6.
//  Copyright © 2019年 Cicel Chen. All rights reserved.
//

#import "CreateGroupActiveTableViewCell.h"

@interface CreateGroupActiveTableViewCell ()

@property (nonatomic, weak)UIView * backView;
@property (nonatomic, weak)UIView * lineView;

@end

@implementation CreateGroupActiveTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    
    return self;
}

- (void)setupUI{
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = ColorWithRGB(0xF0F0F0);
    
    UIView * backView = [UIView new];
    
    backView.backgroundColor  =ZRWhiteColor;
    backView.layer.cornerRadius = 5 * SCREENH6;
    backView.layer.masksToBounds = YES;
    backView.userInteractionEnabled = YES;
    
    self.backView = backView;
    
    [self.contentView addSubview:self.backView];
    
    
    UITextField * textFiled = [[UITextField alloc] init];
    
    textFiled.borderStyle = UITextBorderStyleNone;
    textFiled.backgroundColor = ZRWhiteColor;
//    textFiled.layer.borderColor = [[UIColor clearColor] CGColor];
    //设置光标颜色
    textFiled.tintColor = ZRBlackColor;
    //修改占位符文字颜色
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSForegroundColorAttributeName] = ColorWithRGB(0x909090);
    attrs[NSFontAttributeName] = [UIFont fontWithName:@"PingFangSC-Regular" size:15 * SCREENH6];
    textFiled.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"活动名称（4~16个字）" attributes:attrs];
    textFiled.textColor = ZRBlackColor;
    //    textFiled.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 22 * SCREENH6, 0)];
    //    //设置显示模式为永远显示(默认不显示)
    //    textFiled.leftViewMode = UITextFieldViewModeAlways;
    textFiled.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15 * SCREENH6];

    self.textFiled = textFiled;
    
    [self.backView addSubview:self.textFiled];
    
    
    UIButton * joinButton = [UIButton new];
    
    [joinButton setTitle:@"立即参加" forState:UIControlStateNormal];
    [joinButton setTitle:@"已参加" forState:UIControlStateSelected];
    [joinButton setTitleColor:ColorWithRGB(0xFF5C5C) forState:UIControlStateNormal];
    [joinButton setTitleColor:ZRWhiteColor forState:UIControlStateSelected];
    [joinButton setBackgroundImage:[self imageWithColor:ColorWithRGB(0xFF5C5C)] forState:UIControlStateSelected];
    [joinButton setBackgroundImage:[self imageWithColor:ZRWhiteColor] forState:UIControlStateNormal];
//    joinButton.backgroundColor = ZRWhiteColor;
    joinButton.layer.cornerRadius = 5 * SCREENH6;
    joinButton.layer.masksToBounds = YES;
    joinButton.layer.borderColor = ColorWithRGB(0xFF5C5C).CGColor;
    joinButton.layer.borderWidth = 1.0f;
    joinButton.titleLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    [joinButton addTarget:self action:@selector(clickJoinButton) forControlEvents:UIControlEventTouchUpInside];
    
    self.joinButton = joinButton;
    
    [self.backView addSubview:self.joinButton];
    
    
    UILabel * titleLabel = [UILabel new];
    
    titleLabel.textColor = ZRBlackColor;
    titleLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    
    self.titleLabel = titleLabel;
    
    [self.backView addSubview:self.titleLabel];
    
    
    UILabel * subLabel = [UILabel new];
    
    subLabel.textColor = [UIColor lightGrayColor];
    subLabel.font = [UIFont systemFontOfSize:14 * SCREENH6];
    subLabel.textAlignment = NSTextAlignmentRight;
    
    self.subLabel = subLabel;
    
    [self.backView addSubview:self.subLabel];
    
    
    UIView * lineView = [UIView new];
    
    lineView.backgroundColor = ColorWithRGB(0xe4e4e4);
    
    self.lineView = lineView;
    
    [self.backView addSubview:self.lineView];
}


- (void)layoutSubviews{
    
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.centerX.mas_equalTo(self.contentView);
        make.width.mas_equalTo(345 * SCREENH6);
        make.height.mas_equalTo(50 * SCREENH6);
    }];
    
    [self.joinButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.backView).offset(-10 * SCREENH6);
        make.centerY.mas_equalTo(self.backView);
        make.height.mas_equalTo(30 * SCREENH6);
        make.width.mas_equalTo(80 * SCREENH6);
    }];
    
    [self.textFiled mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.backView).offset(10 * SCREENH6);
        make.trailing.mas_equalTo(self.joinButton.mas_leading).offset(-10 * SCREENH6);
        make.height.mas_equalTo(35 * SCREENH6);
        make.centerY.mas_equalTo(self.backView);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.backView).offset(10 * SCREENH6);
        make.centerY.mas_equalTo(self.backView);
    }];
    
    [self.subLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.backView).offset(-10 * SCREENH6);
        make.width.mas_equalTo(200 * SCREENH6);
        make.centerY.mas_equalTo(self.backView);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.backView).offset(10 * SCREENH6);
        make.trailing.mas_equalTo(self.backView).offset(10 * SCREENH6);
        make.bottom.mas_equalTo(self.backView);
        make.height.mas_equalTo(1 * SCREENH6);
    }];
}

- (void)tapAction{
    
    
}


- (void)clickJoinButton{
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(clickJoinButton)])
    {
        [self.delegate clickJoinButton];
    }
}


- (UIImage *)imageWithColor:(UIColor *)color
{
    
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    
    UIGraphicsBeginImageContext(rect.size);
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    
    CGContextFillRect(context, rect);
    
    
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    
    
    return image;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
